<?php

namespace App\Http\Middleware;

use Closure;

class InstallationGuide
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {

        //判断是否已经安装了博客
        $isInstall = getenv('IS_INSTALL');

        //如果是引导界面,且安装成功了跳转主页
        if (strpos($request->path(), 'install') === 0) {
            return $isInstall == 0 ? $next($request) : redirect('/');
        }
        //未安装跳转到安装引导界面
        if (!$isInstall) {
            return redirect('/install/step1');
        }
        return $next($request);
    }
}
